package com.cg.mapper;

import com.cg.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper {
    
    /**
     * 新增用户
     * @param user 用户信息
     */
    @Insert("INSERT INTO user (username, password, nick_name, email, age, sex, address, expected_address, target_position, expected_salary_min, expected_salary_max, status, create_time, update_time) " +
            "VALUES (#{username}, #{password}, #{nickName}, #{email}, #{age}, #{sex}, #{address}, #{expectedAddress}, #{targetPosition}, #{expectedSalaryMin}, #{expectedSalaryMax}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(User user);
    
    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户信息
     */
    @Select("SELECT * FROM user WHERE username = #{username}")
    User getByUsername(String username);
    
    /**
     * 根据邮箱查询用户
     * @param email 邮箱
     * @return 用户信息
     */
    @Select("SELECT * FROM user WHERE email = #{email}")
    User getByEmail(String email);
    
    /**
     * 根据ID查询用户
     * @param id 用户ID
     * @return 用户信息
     */
    @Select("SELECT * FROM user WHERE id = #{id}")
    User getById(Long id);
}

